﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using AnyOffice.DAL;
using AnyOffice.Components;

namespace AnyOffice.Web.general.netdiskGX
{
    public partial class file_search : BasePage
    {
        private DiskGXDao bll = new DiskGXDao();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bindtype();
            }
        }


        /// <summary>
        /// 类型绑定
        /// </summary>
        public void Bindtype()
        {
            FileTypeDao ft = new FileTypeDao();
            DataSet ds = ft.GetList(base.Conn, string.Empty);
            if (ds.Tables[0].Rows.Count > 0)
            {
                ddl_type.DataSource = ds.Tables[0];
                ddl_type.DataTextField = "FileTypeName";
                ddl_type.DataValueField = "FileTypeID";
                ddl_type.DataBind();
            }
            this.ddl_type.Items.Insert(0, new ListItem("请选择", "-1"));
        }


        /// <summary>
        /// 查询
        /// </summary>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string str = " 1=1";
            if (base.User.Identity.Name != "admin")
            {
                string isCanS = Session["Readid"].ToString().Trim(',');
                isCanS = bll.CanSeeId(base.Conn, isCanS);
                str = " DiskID in(" + isCanS.Trim(',') + ")";
            }
            if (ddl_type.SelectedValue != "-1")
            {
                str += " and FileTypeID=" + ddl_type.SelectedValue + " ";
            }
            if (txt_name.Text.Trim() != "")
            {
                str += " and [Name] like '%" + txt_name.Text.Trim() + "%'";
            }
            if (txt_key.Text.Trim() != "")
            {
                str += " and Keyword like '%" + txt_key.Text.Trim() + "%'";
            }

            if (txtSendTimeMIN.Value != "" && txtSendTimeMAX.Value != "")
            {
                string etime = txtSendTimeMAX.Value + " 23:59:59";
                str += " and UpdateTime between '" + txtSendTimeMIN.Value + "' and '" + etime + "' ";
            }
            if (txtSendTimeMIN.Value != "" && txtSendTimeMAX.Value == "")
            {
                string etime = DateTime.Now.ToShortDateString() + " 23:59:59";
                str += " and UpdateTime between '" + txtSendTimeMIN.Value + "' and '" + etime + "' ";
            }
            if (txtSendTimeMIN.Value == "" && txtSendTimeMAX.Value != "")
            {
                string etime = txtSendTimeMAX.Value + " 23:59:59";
                str += " and UpdateTime <= '" + etime + "' ";
            }

            Response.Redirect("diskfolder.aspx?strsql=" + Server.UrlEncode(str), false);

        }
    }
}